package com.waypolice.manager.service.impl;

import com.waypolice.manager.service.RoleResourcesService;
import com.waypolice.mapper.UpmsPermissionMapper;
import com.waypolice.mapper.UpmsRolePermissionMapper;
import com.waypolice.pojo.UpmsPermission;
import com.waypolice.pojo.UpmsRolePermission;
import com.waypolice.pojo.UpmsRolePermissionExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 角色权限管理接口实现
 * @author zhangxiaoyang
 *
 */
@Service
public class RoleResourcesServiceImpl implements RoleResourcesService {
	
	@Autowired
    private UpmsRolePermissionMapper upmsRolePermissionMapper;

	@Autowired
    private UpmsPermissionMapper upmsPermissionMapper;

	@Override
	public String findResourceByRoId(String roId) {
        UpmsRolePermissionExample upmsRolePermissionExample = new UpmsRolePermissionExample();
        UpmsRolePermissionExample.Criteria criteria1 = upmsRolePermissionExample.createCriteria();
        criteria1.andRoleIdEqualTo(Integer.valueOf(roId));
        List<UpmsRolePermission> upmsRolePermissions = upmsRolePermissionMapper.selectByExample(upmsRolePermissionExample);
		String resourceStr ="";
		for (UpmsRolePermission  upmsRolePermission:upmsRolePermissions){
			Integer permissionId = upmsRolePermission.getPermissionId();
            UpmsPermission upmsPermission = upmsPermissionMapper.selectByPrimaryKey(permissionId);
            String name = upmsPermission.getName();
			if("".equals(resourceStr)){
				resourceStr = name;
			}else{
				resourceStr+=","+name;
			}
		}
		return resourceStr;
	}

}
